<? 
  require('includes/class.main.php');
  $manager = new MeetingManager();
  $lookup = new MeetingLookup();
  $cities = $lookup->getCities();
  $zips = $lookup->getZips();
  $zip = "";
  $city = "";
  $name = "";
  $return = "";
  $display_zip = "";
  $locations = $lookup->getClubhouses();

  if (isset($_POST['submit']) == "Search") {
    $location = trim($_POST['location']);
    $name = trim($_POST['name']);
    $city = $_POST['city'];
    $zip = $_POST['zip'];
    $day = $_POST['day'];
    $time = $_POST['time'];
    $meridian = $_POST['meridian'];
    $codes = $_POST['codes'];
  }

  if (isset($_POST['simple']) == "Search") {
    $name = $_POST['name'];
    $day = $_POST['day'];
    $time = $_POST['time'];
    $terms = $_POST['terms'];

    $data = $lookup->parseTerms($terms);
    $city = strtoupper(($data[0]));
    $zip = $data[1];
  }

  if ($city == "CITY") { $city = ""; }


  include_once 'template/header.php';
?>		
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />  
  <title>Alcoholics Anonymous</title>
  <link rel="shortcut icon" href="/favicon.ico">
  <link rel="stylesheet" href="css/style.css" type="text/css" />
  <script language="javascript" type="text/javascript" src="javascript/site.js"></script>
</head>

<body>
<div class="content">
  <div class="header_right">
    <div class="top_info">
    <div class="top_info_right">
  </div>		
</div>
					
<div class="bar">
  <ul>
  <li><a href="index.php" accesskey="b">Home</a></li>
  <li><a href="calendar.php" accesskey="a">Calendar</a></li>
  <li><a href="store.php" accesskey="a">Store</a></li>
  <li><a href="meetings.php" accesskey="p">Meetings</a></li>
  <li><a href="contact.php" accesskey="g">Contact Us</a></li>
  </ul>
  			<span style="font-weight: bold; font-style: italic; padding-right: 3em; line-height: 3em;">
			Try our new <a href="search.php">Meetings Search (Beta)!</a>
			</span>		
  
</div>

</div>
  <div class="logo">
  <h1><a href="#" title="Alcoholics Anonymous">Alcoholics <span class="blue">Anonymous</span></a></h1>
  <center><h3>Central Office of Atlanta, Georgia</h3></center>
  </div>
		
  <div>
  <div class="search_field">
  <form method="post" action="meetings.php">
  <p><span class="grey">Find a Meeting:</span> <span class="search"></span>&nbsp;&nbsp; 
  <input type="text" name="terms" id="terms" class="search" value="CITY, ZIP" onClick="clearSimpleSearch();" onBlur="fillSimpleSearch();"/> 
  <input type="submit" name="simple" value="Search" class="button" /></p>
  </form>
  </div>
		
  <div class="newsletter">
  <p>&nbsp;</p>
  </div>
  </div>
		
  <div class="subheader">
  </div>


<div class="subheader">
  <div>
  <form method="post">
  <b><span class="blue">Search for Meetings</span></b>
  <br><br>
 
  <table width="100%">
   <tr>
   <td>Location </td>
   <td>
      <select name="location">
        <?
          if ($location != "") {
            if ($location == "%") {
              $display_location = "";
            } else {
              $display_location = $location;
            }
            echo "<option value='$location' selected>$display_location</option>";
          }
        ?>
      <? echo $locations; ?>
      </select>
   </td>

    <!-- select * from meetings where find_in_set('B',codes) > 0 and find_in_set('BB',codes) > 0; -->
    <td rowspan=6 valign="top" align="right">Meeting Codes <br><i>(hold CTRL for multiple)</i></td>
    <td rowspan=6 valign="top">
        <select name="codes[]" multiple size=7>

	<?
	   $any_selected = "";
	   $o_selected = "";
	   $c_selected = "";
	   $b_selected = "";
	   $s_selected = "";
	   $t_selected = "";
	   $bb_selected = "";
	   $d_selected = "";
	   $od_selected = "";
	   $cd_selected = "";

	   if (!empty($codes)) {
		   foreach ($codes as $code) {
		     if ($code == "%") { $any_selected = "selected"; }
		     if ($code == "O") { $o_selected = "selected"; }
		     if ($code == "C") { $c_selected = "selected"; }
		     if ($code == "B") { $b_selected = "selected"; }
		     if ($code == "S") { $s_selected = "selected"; }
		     if ($code == "T") { $t_selected = "selected"; }
		     if ($code == "BB") { $bb_selected = "selected"; }
		     if ($code == "D") { $d_selected = "selected"; }
		     if ($code == "OD") { $od_selected = "selected"; }
		     if ($code == "CD") { $cd_selected = "selected"; }
		     if ($code == "OS") { $os_selected = "selected"; }
		     if ($code == "YP") { $yp_selected = "selected"; }
		     if ($code == "G") { $g_selected = "selected"; }
		     if ($code == "HA") { $w_selected = "selected"; }
		     if ($code == "M") { $mo_selected = "selected"; }
		     if ($code == "W") { $wo_selected = "selected"; }
		     if ($code == "WM") { $wm_selected = "selected"; }
		     if ($code == "DF") { $df_selected = "selected"; }
		     if ($code == "CP") { $cp_selected = "selected"; }
		     if ($code == "LM") { $lm_selected = "selected"; }
		     if ($code == "SP") { $sp_selected = "selected"; }
		     if ($code == "GV") { $gv_selected = "selected"; }
		     if ($code == "A") { $a_selected = "selected"; }
		     if ($code == "RU") { $ru_selected = "selected"; }
		   }
	   }
	   	
	   if (empty($codes)) { $any_selected = "selected"; }
  

	?>

        <option value="%" <? echo $any_selected; ?>> Any </option>
        <option value="O" <? echo $o_selected; ?>> Open (O)</option>
        <option value="C" <? echo $c_selected; ?>> Closed (C)</option>
        <option value="B" <? echo $b_selected; ?>> Beginners (B)</option>
        <option value="S" <? echo $s_selected; ?>> Steps (S)</option>
        <option value="T" <? echo $t_selected; ?>> Traditions (T)</option>
        <option value="BB" <? echo $bb_selected; ?>> Big Book (BB)</option>
        <option value="D" <? echo $d_selected; ?>> Discussion (D)</option>
        <option value="OD" <? echo $od_selected; ?>> Open Discussion (OD)</option>
        <option value="CD" <? echo $cd_selected; ?>> Closed Discussion (CD)</option>
        <option value="OS" <? echo $os_selected; ?>> Open Speaker (OS)</option>
        <option value="YP" <? echo $yp_selected; ?>> Young People (YP)</option>
        <option value="G" <? echo $g_selected; ?>> Gay / All Welcome (G)</option>
        <option value="HA" <? echo $w_selected; ?>> Handicap Accessible (HA)</option>
        <option value="M" <? echo $mo_selected; ?>> Men's Meeting (M)</option>
        <option value="W" <? echo $wo_selected; ?>> Women's Meeting (W)</option>
        <option value="WM" <? echo $wm_selected; ?>> Women / All Welcome (WM)</option>
        <option value="DF" <? echo $df_selected; ?>> Sign Language Interpreted (DF)</option>
        <option value="CP" <? echo $cp_selected; ?>> Couples (CP)</option>
        <option value="LM" <? echo $lm_selected; ?>> Lunch Meeting (LM)</option>
        <option value="SP" <? echo $sp_selected; ?>> Spanish (SP)</option>
        <option value="GV" <? echo $gv_selected; ?>> Grapevine (GV)</option>
        <option value="A" <? echo $a_selected; ?>> Al-Anon (A)</option>
        <option value="RU" <? echo $ru_selected; ?>> Russian (RU)</option>
	</select>

	<br>
    </td>

    <tr>
    <td>Group</td>
    <td><input type="text" name="name" value="<? echo $name; ?>"></td>
    </tr>

    <tr>
    <td>City</td>
    <td>
      <select name="city">
        <?
          if ($city != "") {
            if ($city == "%") {
              $display_city = "";
            } else {
              $display_city = $city;
            }
            echo "<option value='$city' selected>$display_city</option>";
          }
        ?>
      <? echo $cities; ?>
      </select>
    </td>
    </tr>

    <tr>
	<?
          if ($zip != "") {
            if ($zip == "%") {
              $display_zip = "";
            } else {
              $display_zip = $zip;
            }
	  }
	?>
    <td>Zip</td>
    <td><input type="text" name="zip" value="<? echo $display_zip; ?>"></td>
    </tr>

    <tr>
    <td>Day</td>
    <td>
      <select name="day">
	<?
	  if ($day != "") {
            if (preg_match("/%/",$day)) {
              $display_day = "";
            } else {
              $display_day = $day;
	    }
	    echo "<option value='$day' selected>$display_day</option>";
	  }
	?>
      <option value="%"></option>
      <option>SUNDAY</option>
      <option>MONDAY</option>
      <option>TUESDAY</option>
      <option>WEDNESDAY</option>
      <option>THURSDAY</option>
      <option>FRIDAY</option>
      <option>SATURDAY</option>
      </select>
    </td>
    </tr>

    <tr>
    <td>Time</td>
    <td>
      <select name="time">
	<?
	  if ($time != "") {
	    if(!preg_match("/:00$/",$time)) {
	      $display_time = $time . ":00";
	    }
	    if (preg_match("/%/",$time)) {
	      $display_time = "";
	    }
	    echo "<option value='$time' selected>$display_time</option>";
	  }
	  if ($time == "%") {
	    $display_time = "";
	  }
	?>
      <option value="%"></option>
      <option value="1">1:00</option>
      <option value="2">2:00</option>
      <option value="3">3:00</option>
      <option value="4">4:00</option>
      <option value="5">5:00</option>
      <option value="6">6:00</option>
      <option value="7">7:00</option>
      <option value="8">8:00</option>
      <option value="9">9:00</option>
      <option value="10">10:00</option>
      <option value="11">11:00</option>
      <option value="12">12:00</option>
      </select>

      <select name="meridian">
	<?
	  if ($meridian != "") {
	    if ($meridian == "%") {
	      $display_meridian = "";
	    } else {
	      $display_meridian = $meridian;
	    }
	    echo "<option value='$meridian' selected>$display_meridian</option>";
	  }
	?>
      <option value="%"></option>
      <option>AM</option>
      <option>PM</option>
      </select>
    </td>
    </tr>

    <tr>
      <td colspan=4 align="Center">
        <input type="submit" name="submit" value="Search">
      </td>
    </tr>

  </table>

  </form>
  </div>

</div>

<div>

	<?
	if (isset($_POST['submit']) == "Search") {
		$i = 1;
		$return = $lookup->detailedSearch($location, addslashes($name), $city, $zip, $day, $time, $meridian, $codes);
	} elseif (isset($_POST['simple']) == "Search!") {
		$i = 1;
		$return = $lookup->simpleSearch($city,$zip);
	} else {
		echo "<center>Search fields are not required.  Leave search form blank for all results, and fill in select fields to narrow down search results</center><br>\n";
	}

	if ($return != "") {
		if ($return[1] == 1) {
			$meetings = "meeting";
		} else {
			$meetings = "meetings";
		}

		if ($return[1] == 0) {
			echo "<center>$return[1] $meetings found. Please change your search criteria and try again.</center><br>\n";
		} else {
			echo "<center>$return[1] $meetings found. Click on meeting name for map and directions. Scroll over meeting codes for full descriptions.</center><br>\n";
		}

		echo "<table width=100% cellspacing=10>\n";
		$day_state = "";
		while ($row = $return[0]->fetch_row()) {
			if($i % 2) {
				$bgcolor = "#F4F4F4";
			} else {
				$bgcolor = "#FFFFFF";
			}

			if ($day_state != $row[9]) {
				echo "<tr bgcolor='#094EAA'>\n";
				echo "<td colspan=6><b><font color='#ffffff'>$row[9]</font></td>\n";
				echo "</tr>\n";
				//next;
			}

			echo "<tr bgcolor='$bgcolor'>\n";
			echo "<td><a href=\"map.php?row=$row[0]\">$row[10]</a></td>\n";
			echo "<td><a href=\"map.php?row=$row[0]\">$row[6]</a></td>\n";
			echo "<td><a href=\"map.php?row=$row[0]\">$row[7]</a></td>\n";

			$club = $row[2];
			if (strlen($club) > 18) {
				$club = substr($club, 0, 17) ."...";
			}

			$meet = $row[1];
			if (strlen($meet) > 18) {
				$meet = substr($meet, 0, 17) ."...";
			}

			echo "<td><a href=\"map.php?row=$row[0]\">$club</a></td>\n";
			echo "<td><a href=\"map.php?row=$row[0]\">$meet</a></td>\n";
			echo "<td><a href=\"javascript:\" style=\"text-decoration: none; font-weight: bold;\" onMouseOver=\"translateCodes('".$row[11]."','popup".$i."');\" id=\"popup".$i."\" title=\"\">$row[11]</a></td>\n";
			echo "</tr>\n";

			$city_state = $row[6];
			$zip_state = $row[7];
			$day_state = $row[9];
			$i++;
		}
		echo "</table>\n";
	}
	?>


</div>	
	
	</div>	
		<div class="footer">
			<p><a href="http://aa.org/">World Services</a> | 
			<a href="http://www.aageorgia.org/">Georgia A.A.</a> | 
			<a href="http://www.aa.org/bigbookonline/">Big Book Online</a> | 
			<a href="http://www.aagrapevine.org/">Grapevine</a> | 
			<a href="admin/">Admin</a> | 
			<a href="#">Disclaimer</a> <br>
                        <p style="font-size: 90%">
                        This is the official web site of the Atlanta Central Office of Alcoholics Anonymous.
                        </p>
		</div>

<!-- google analytics -->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-39354567-1']);
  _gaq.push(['_setDomainName', 'atlantaaa.org']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

</body>
</html>
